<?php 
defined('IN_DESTOON') or exit('Access Denied');
login();
require DT_ROOT.'/module/'.$module.'/common.inc.php';             
$table = $DT_PRE.'purchase_price'; 
$table_b = $DT_PRE.'buy_6'; 
$status = $_REQUEST['status'];
$itemid = $_REQUEST['itemid'];
switch($action){
    case 'pass':
            $id = $_REQUEST['id'];
          if(!empty($id)&&!empty($itemid)){
                $db->query("update $table set status = 40 where  buy_6_id = {$itemid} and id !={$id}");
               // var_dump("update $table set status = 30 where  buy_6_id = {$itemid} and id ={$id}");exit;
                $db->query("update $table set status = 30 where  buy_6_id = {$itemid} and id ={$id}");
                $db->query("update $table set status = 40 where  buy_6_id = {$itemid} and id !={$id}");
                $db->query("update $table_b set status = 8,purchase_price_id= {$id} where itemid = {$itemid} ");
            }
            dmsg("操作成功", 'my.php?mid=6');
        break;
        default :
               
                if(!empty($status)){
                    $condition = ' AND b.status = '.$status;
                }
                if(empty($itemid)){
                     $condition .= ' AND b.user_id = '.$_userid;
                     $sql = "SELECT a.title title,a.amount amount,a.price price,a.company company,a.truename truename,b.price price1,b.add_time add_time,b.status status,b.id id  FROM {$table_b} a,{$table} b WHERE a.itemid = b.buy_6_id ".$condition;
                }else{
                   $condition .= ' AND b.buy_6_id = '.$itemid;
                   $sql = "SELECT a.title title,a.status flag,a.amount amount,a.price price,b.company_name company,b.user_name truename,b.price price1,b.add_time add_time,b.status status,b.id id  FROM {$table_b} a,{$table} b WHERE a.itemid = b.buy_6_id ".$condition;
                }
                $r = $db->get_one("SELECT COUNT(*) AS num FROM {$table} where 1=1  $condition");
                $pages = pages($r['num'], $page, $pagesize);	 
                $lists = array();
               
                $result = $db->query("$sql ORDER BY id  DESC LIMIT $offset,$pagesize");
                 while($r = $db->fetch_array($result)) {
                   // $r['dstatus'] = $_send_status[$r['send_status']];
                    $lists[] = $r;
                }
        break;
   
}
include template('purchase', $module);
?>